require('../css/common/normalize.css')
require('../css/common/reset.css')
require('../css/common/property.css')
require('../css/common/basic.less')
require('../lib/fonts/iconfont.css')
require('../css/pwdLogin.less')

// meui 库

require('weui')
const weui = require("weui.js")


//axios
const axios = require('axios')



//获取元素

const loginPhone=document.querySelector('#login-phone')
const loginPwd=document.querySelector('#login-pwd')
const loginBtn=document.querySelector('#login-btn')
const judge=document.querySelector('.judge')


loginBtn.addEventListener('click',function(){

    //获取输入值
 
    const loginPhoneVal=loginPhone.value
    console.log(loginPhoneVal);
    const loginPwdVal=loginPwd.value

    if(!/^1[3-9][0-9]{9}$/.test(loginPhoneVal)){  //验证手机号
        judge.textContent='手机号不正确'
        return

    }else if(!/^[a-zA-Z]\w{5,11}$/.test(loginPwdVal)){  //密码
        judge.textContent='密码输入不正确'
        return
    }else{
        //清除验证
        judge.textContent=''

        axios.post('http://139.9.177.51:8099/users/login',{
            account:loginPhoneVal,
            password:loginPwdVal

        }).then(function(res){
            console.log(res);
            if(res.data.status===0){
                localStorage.setItem('userId',res.data.data.user.userId)
                console.log(res.data.data.user.userId);
                //轻提示
                weui.toast('登陆成功',{

                    duration:1000,
                    callback:function(){
                        //注册成功提示
                    location.href='./home.html'
                    loginPhoneVal=loginPwdVal=''

                    }
                })
                
            }else{
                //出现轻提示
                weui.alert(res.data.msg)
            }

        })
    }

})


